/**
 * Created by jiaaobo on 16/11/29.
 */
import Util from "util";
import API  from "api";
import  constant  from "const";
import CDSev from "../../../common/util/seckill";

let currentTimerObj;

export default{
  data(){
    return{
      orderInfo : {},
      orderResult  : constant.ORDER_RESULT_STATUS,
      seckillMsg : ""
    }

  },

  mounted : function(){

    //测试
    // this.orderInfo = {
    //   state :  3,
    //   times : 30 * 60 ,
    //   overtimeCost : 1.3
    // }

    this.orderInfo = Util.Storage.getSgObj("orderResult");
    if(!this.orderInfo){
      Util.UI.toast("数据异常!");
      return;
    }

    if(this.orderInfo.state == constant.ORDER_RESULT_STATUS.RUNNING){

      console.log('剩余秒',this.orderInfo.times);

      let endTime = new Date().getTime() + this.orderInfo.times * 1000;

      //倒计时
      currentTimerObj = CDSev.createTimer(endTime,(date)=>{
        this.seckillMsg = date;
      },(date)=>{

        this.orderInfo.state = constant.ORDER_RESULT_STATUS.END;

      },"orderResultTimer");

    }




  },

  beforeDestroy : function(){
    if(currentTimerObj)
      CDSev.clearTimer(currentTimerObj.id);
  },

  methods : {

  },
  computed : {
      getOutTime(){
        let time = CDSev.getTimerString(this.orderInfo.times * 1000);
        return time.substring(0,time.length -3);

      }
  },
  components:{

  }
}
